package com.zebra.base.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zebra.base.po.BaseEntity;
import org.springframework.beans.BeanUtils;

/**
 * @ClassName BaseForm
 * @Description TODO Vo层父类
 * @Author 消魂钉
 * @Date 5/26 0026 14:56
 */
public class BaseForm<T extends BaseEntity> {

    protected CopyOptions nullValueOptions = CopyOptions.create().setIgnoreNullValue(true);

    /**
     * Form转化为Po对象 空属性不做转化
     *
     * @param clazz
     * @return
     */
    public T toPo(Class<T> clazz) {
        return toPo(clazz,nullValueOptions);
    }

    /**
     * Form转化为Po对象 空属性不做转化
     *
     * @param clazz
     * @return
     */
    public T toPo(Class<T> clazz,CopyOptions options) {
        T p = ReflectUtil.newInstance(clazz);
        BeanUtil.copyProperties(this,p, options);
        return p;
    }

}
